/*
 * Copyright user2010
 * All rights reserved
 */

package org.myorg.applitest.jdbc;

import org.myorg.applitest.mysql.MysqlSettings;

/**
 *
 * @author user
 */
public class Def {



    final static public String formatField(String strField) {
       String str="";
       if (strField.isEmpty()){
           str = strNull;
       }
       else {
            str= "'" + strField + "'";
       }

       return str;
    }
    public static String createField(String strField, String strType){
        return strField + strBlank + strType + strComma;
    }
    public static String createLastField(String strField, String strType){
        return strField + strBlank + strType + strEndCommand;
    }
    public static String addField(String strField){
        return  formatField(strField) + strFieldSep;
    }
    public static String addLastField(String strField){
         return formatField(strField) + strEndCommand ;
    }
    final static public String countElements(String strTable){
        return strSelect + strBlank + 
               strCount + intoPar(strStar) + strBlank +
               strFrom + strBlank +
               strTable + strEnd;
    }
    final static public String insertIntoTable(String strTable){
        return strInsert + strBlank +
               strInto + strBlank +
               strTable + strBlank +
               strValues + strBlank +
               strRightPar;
    }
    final static public String createDB(String strDB){
        return strCreateDB + strDB  + strEnd;
    }

    final static public String dropDB(String strDB){
        return strDropDB + strDB;
    }

    final static public String useDB(String strDB){
        return strUseDB + strBlank +strDB;
    }

    final static public String createTable(String strTable){
        return strCreateTable + strTable + strRightPar;
    }

    final static public String dropTable(String strTable){
        return strDropTable + strTable;
    }


    /****************************************************************************
   *                  Definition of string for mysql types                    *
   ****************************************************************************/

    final static private String _STR_VAR = "VAR";

    final static public String strTypChar = "CHAR";
    final static public String strTypBinary = "BINARY";

    final static public String strTypVarChar = _STR_VAR + strTypChar;
    final static public String strTypVarBinary = _STR_VAR + strTypBinary;

    final static private String strTiny = "TINY";
    final static private String strMedium = "MEDIUM";
    final static private String strLong = "LONG";

    final static private String strTypBlob = "BLOB";
    final static private String strTypTinyBlob = strTiny + strTypBlob;
    final static private String strTypMediumBlob = strMedium + strTypBlob;
    final static private String strTypLongBlob = strLong + strTypBlob;
    final static private String strTypText = "TEXT";
    final static private String strTypTinyText = strTiny + strTypText;
    final static private String strTypMediumText = strMedium + strTypText;
    final static private String strTypLongText = strLong + strTypText;

    final static private String strTypEnum = "ENUM";
    final static private String strTypSet = "SET";
    final static public String strTypDate = "DATE";


    final static public String typDate(){
        return strTypDate;
    }

     final static public String typVarchar(Integer size){
         System.out.println(size);
        if (size < MysqlSettings.minLengthChar || size > MysqlSettings.maxLenghtChar)
        {
            return "TODO";
        }
        else {
            return strTypVarChar +sz(size);
        }
    }
    final static public String typChar(Integer size){ return strTypChar +sz(size);}

    final static public String typId = "SMALLINT UNSIGNED NOT NULL AUTO_INCREMENT primary key";
    final static public String typRefId(String strtable, String strField){
        return "SMALLINT UNSIGNED NOT NULL REFERENCES" + strBlank +strtable +intoPar(strField);};
    


    /****************************************************************************
   *                 Definition of string for mysql commands                  *
   ****************************************************************************/

    final static private String strInsert = "INSERT";
    final static private String strSelect = "SELECT";
    final static private String strCreate = "CREATE";
    final static private String strCount = "COUNT";
    final static private String strDrop = "DROP";
    final static private String strUseDB = "USE";
    final static private String strCmdShow = "SHOW";




    /****************************************************************************
   *                 Definition of string for mysql keywords                  *
   ****************************************************************************/

    final static public String strNull = "NULL";

    final static public String idVal = "1";

    final static private String strLeftPar = ")";
    final static private String strRightPar = "(";
    final static private String strComma = ",";
    final static private String strEnd = ";";
    final static private String strStar = "*";
    final static private String strBlank = " ";
    final static private String strDB = "DATABASE";
    final static private String strTable = "TABLE";
    final static private String strValues = "VALUES";
    final static private String strInto = "INTO";
    final static private String strFrom = "FROM";

    final static public String strFieldSep = strComma + strBlank;
    final static private String strEndCommand =  strLeftPar+strEnd;
    final static private String strDropTable = strDrop + strBlank + strTable + strBlank;
    final static private String strCreateTable = strCreate + strBlank + strTable + strBlank;
    final static private String strCreateDB = strCreate + strBlank + strDB + strBlank;
    final static private String strDropDB = strDrop + strBlank + strDB +strBlank;



    /****************************************************************************
   *                  Definition of string for string utils                   *
   ****************************************************************************/

    final static private String sz(Integer size){
        return strRightPar + size.toString() + strLeftPar;
    }
    final static private String intoPar(String str){
        return strRightPar + str + strLeftPar;
    }




}
